| Conditions | 3 |
| Total Lines | 86 |
| Code Lines | 70 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | import { useState, useEffect } from 'react'; |
||
| 11 | |||
| 12 | |||
| 13 | export default function HistoryMap({navigation, journey, modalVisible, setModalVisible}): any { |
||
| 14 | const [startCoordinates, setStartCoordinates] = useState([]); |
||
| 15 | const [endCoordinates, setEndCoordinates] = useState([]); |
||
| 16 | |||
| 17 | console.log(journey); |
||
| 18 | |||
| 19 | useEffect(() => { |
||
| 20 | function setCoordinates() { |
||
| 21 | if (modalVisible) { |
||
| 22 | setStartCoordinates(journey['startPosition']); |
||
| 23 | setEndCoordinates(journey['endPosition']); |
||
| 24 | } |
||
| 25 | |||
| 26 | }; |
||
| 27 | |||
| 28 | setCoordinates(); |
||
| 29 | }) |
||
| 30 | |||
| 31 | return ( |
||
| 32 | <Modal |
||
| 33 | animationType="slide" |
||
| 34 | transparent={true} |
||
| 35 | visible={modalVisible} |
||
| 36 | onRequestClose={() => { |
||
| 37 | setModalVisible(!modalVisible) |
||
| 38 | }} |
||
| 39 | > |
||
| 40 | <View style={styles.container}> |
||
| 41 | |||
| 42 | <MapView |
||
| 43 | style={styles.map} |
||
| 44 | // region={{ |
||
| 45 | // // latitude: position.latitude? position.latitude : 0, |
||
| 46 | // // longitude: position.longitude? position.longitude : 0, |
||
| 47 | // // latitudeDelta: 0.03, |
||
| 48 | // // longitudeDelta: 0.03, |
||
| 49 | // }} |
||
| 50 | userInterfaceStyle={'dark'} |
||
| 51 | > |
||
| 52 | <Marker |
||
| 53 | coordinate={{latitude: startCoordinates[0], longitude: startCoordinates[1]}} |
||
| 54 | /> |
||
| 55 | |||
| 56 | <Marker |
||
| 57 | coordinate={{latitude: endCoordinates[0], longitude: endCoordinates[1]}} |
||
| 58 | /> |
||
| 59 | </MapView> |
||
| 60 | |||
| 61 | <View style={styles.infoContainer}> |
||
| 62 | <Pressable style={[styles.backButton, styles.shadowProp]} onPress={() => setModalVisible(false)}> |
||
| 63 | <Icon |
||
| 64 | name='arrow-left' |
||
| 65 | size={25} |
||
| 66 | color='black' |
||
| 67 | /> |
||
| 68 | </Pressable> |
||
| 69 | <View style={styles.info}> |
||
| 70 | |||
| 71 | <View style={styles.listInfo}> |
||
| 72 | <Text style={styles.infoTitle}>Journey started</Text> |
||
| 73 | <Text>{journey.date}</Text> |
||
| 74 | </View> |
||
| 75 | |||
| 76 | <View style={styles.listInfo}> |
||
| 77 | <Text style={styles.infoTitle}>Information about the trip</Text> |
||
| 78 | <Text>{mapModel.calcDistance(startCoordinates[0], startCoordinates[1], endCoordinates[0], endCoordinates[1])} km / {journey.totalMin} min </Text> |
||
| 79 | |||
| 80 | <Text> {journey.totalPrice} kr</Text> |
||
| 81 | </View> |
||
| 82 | |||
| 83 | <View style={styles.listInfo}> |
||
| 84 | <Text style={styles.infoTitle}>ID</Text> |
||
| 85 | <Text>{journey['_id']}</Text> |
||
| 86 | </View> |
||
| 87 | |||
| 88 | <View style={styles.listInfo}> |
||
| 89 | <Text style={styles.infoTitle}>Vehicle</Text> |
||
| 90 | <Text>{journey.scooterName}</Text> |
||
| 91 | </View> |
||
| 92 | |||
| 93 | </View> |
||
| 94 | </View> |
||
| 95 | </View> |
||
| 96 | </Modal> |
||
| 97 | |||
| 167 |